
package progentiere.knapsackprb;

import java.util.ArrayList;
import java.util.Random;

public class KnapSackProblem 
{

    private int nbItems;
    private double capacity;
    private ArrayList<Item> items;
    private Solution solution;
    private Algorithm algo;

    public KnapSackProblem(int capacity, int nbItems, Algorithm algo) 
    {
        this.nbItems = nbItems;
        this.capacity = capacity;
        this.items = new ArrayList<>();
        this.solution = new Solution(nbItems);
        this.algo = algo;        
    }
    
    public void generateAtRandom(int seed, double deviation)
    {
        Random generator = new Random(seed);
        
        for(int i = 0 ; i < this.nbItems ; i++)
        {
            Item newItem = new Item();
            newItem.generateAtRandom(this.capacity, generator, deviation);
            this.items.add(newItem);
        }
    }

    public int getNbItems() 
    {
        return nbItems;
    }

    public double getCapacity() 
    {
        return capacity;
    }

    public ArrayList<Item> getItems() 
    {
        return items;
    }

    public Solution getSolution() 
    {
        return solution;
    }

    public void solve()
    {
        this.solution = this.algo.solve(this);
    }
    
    public Algorithm getAlgo() 
    {
        return algo;
    }

    @Override
    public String toString() 
    {
        return "KnapSackProblem{" + "nbItems=" + nbItems + ", capacity=" + capacity + ",\n items=" + items + ",\n solution=" + solution + ", algo=" + algo + '}';
    }
    
    
}
